<?php
namespace Lib;
define ( 'LIB', __DIR__ );
require_once LIB . '/ExceptionExt.class.php';
/**
 *
 * @author ximi
 *        
 */
class Base {
	/**
	 * 构造函数
	 *
	 * @param string $sConfigFile        	
	 */
	public function __construct($sConfigFile = null) {
		if ($sConfigFile) {
			$this->Config->init ( $sConfigFile, true );
		}
		$this->Server->initSession ();
	}
	
	/**
	 * 获取方法
	 *
	 * @param string $sClassName        	
	 * @return object boolean
	 */
	public function __get($sClassName) {
		$aType = array (
				'Lib',
				'Model',
				'Action' 
		);
		if (in_array ( $sClassName, $aType )) {
			require_once __DIR__ . '/' . $sClassName . '.class.php';
			$sClass = __NAMESPACE__ . '\\' . $sClassName;
			$oObj = new $sClass ();
			$this->__set ( $sClassName, $oObj );
			return $oObj;
		} else {
			foreach ( $aType as $sType ) {
				if (defined ( strtoupper ( $sType ) )) {
					$sFile = constant ( strtoupper ( $sType ) ) . '/' . $sClassName . '.class.php';
					$sDir = constant ( strtoupper ( $sType ) ) . '/' . $sClassName;
					if (is_file ( $sFile ) || is_dir ( $sDir )) {
						return $this->$sType->$sClassName;
					}
				}
			}
		}
		return false;
	}
	
	/**
	 * 将方法保存到属性
	 *
	 * @param string $sName        	
	 * @param object $sValue        	
	 */
	public function __set($sName, $oValue) {
		$this->$sName = $oValue;
	}
}